<?php
	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";
	echo $this->renderElement('message');
	
	if ($othAuth->hasPermission('volunteers/add/')) {
		echo '<div> Cadastre os voluntários manualmente em "Cadastrar Voluntário" ou envie um convite por e-mail em "Convidar Voluntário".<br/><br/></div>';
		$addButton = "<span class=\"buttonAdd\">Cadastrar voluntário</span>";
		echo html_entity_decode($html->link($addButton, '/volunteers/add/',array('class'=>'button')));
		
		$inviteButton = "<span class=\"buttonAdd\">Convidar voluntário</span>";
		echo html_entity_decode($html->link($inviteButton, '/volunteers/invite/',array('class'=>'button')));
	}

	if (isset($volunteers) && is_array($volunteers) && (!empty($volunteers))) {
		echo "<br />";
		echo "<table>";

		/* Cabeçalho */
		echo "<thead>";
		echo "<div></div>";
		echo "<tr class='tableHeader'>";
		echo "<th class='tableHeaderBegin'>Nome</th>";
		echo "<th class='tableHeaderMiddle'>Unidade</th>";
		if ($othAuth->hasPermission('volunteers/edit/')) {
			echo "<th class='tableHeaderMiddle'>Editar</th>";
		}
		if ($othAuth->hasPermission('volunteers/delete/')) {
			echo "<th class='tableHeaderEnd'>Excluir</th>";
		}
		echo "</tr>";
		echo "</thead>";
		
		/* Rodapé */
		echo "<tfoot>";
		echo "<tr class='tableFooter'>
		<td colspan='100%'></td>
		</tr>";
		echo "</tfoot>";
		
		
		$i=0;
		foreach ($volunteers as $volunteer) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td>".$html->link($volunteer['User']['name'],'/volunteers/view/'.$volunteer['Volunteer']['id'])."</td>";
			echo "<td>";
			foreach($volunteer['User']['Unit'] as $unit) {
				echo $html->link($unit['nome'],'/units/view/'.$unit['id'])."<br>";
			}
			echo "</td>";
			if ($othAuth->hasPermission('volunteers/edit/')) {
				echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'icon')), '/volunteers/edit/'.$volunteer['Volunteer']['id']))."</td>";
			}
			if ($othAuth->hasPermission('volunteers/delete/')) {
				echo "<td class='tdCenter'>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'icon')), '/volunteers/delete/'.$volunteer['Volunteer']['id'], array(), 'Confirma a exclusão deste item?'))."</td>";
			}
			echo "</tr>";
		}
		echo "</table>";
	} else {
		echo "<p>Não há nenhum voluntário cadastrado.</p>";
	}
?>
